package com.example.siyun.controller.permissionscontroller;

import com.example.siyun.config.Log;
import com.example.siyun.pojo.EnumPojo;
import com.example.siyun.pojo.FeedBackList;
import com.example.siyun.service.permissionsservice.FeedbacklistService;
import com.example.siyun.util.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Auther: 全
 * @Date: 2022/9/26 09:33
 * @Description:权限管理模块反馈管理里面的反馈列表
 */
@Slf4j
@RestController
public class FeedbacklistController {
    @Autowired
    private FeedbacklistService feedbacklistService;
    /**
     * 获取反馈列表的信息
     * @return 反馈反馈列表的信息
     */
    @Log
    @RequestMapping("/advanced/getfeedbacklist")
    public PageResult getFeedBackList(int page, int limit, FeedBackList feedbacklist) {
        log.info("获取反馈列表的信息");
        PageHelper.startPage(page, limit);
        System.out.println(this);
        List<FeedBackList> list = feedbacklistService.getFeedBackList(feedbacklist, EnumPojo.VALUE_DEL_0,EnumPojo.VALUE_DEL_1);
        PageInfo<FeedBackList> pageInfo = new PageInfo<>(list);
        PageResult pageResult=new PageResult();
        pageResult.setState(0);
        pageResult.setMessage("成功");
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setData(pageInfo.getList());
        log.info("获取反馈列表的信息成功");
        return pageResult;
    }
    @RequestMapping("/advanced/selectfeedbackstate")
    public Map<String, Object> selectFeedBackState() {
        System.out.println(this);
        Map<String, Object> selectdata = feedbacklistService.selectFeedState(EnumPojo.STATE_0, EnumPojo.STATE_1);
        return selectdata;
    }
    /**
     * 通过id修改反馈列表的反馈状态
     * @param  id 要修改反馈列表的id
     */
    @RequestMapping("/advanced/updatebackstate")
    public PageResult updateBackState(int id){
        log.info("通过id修改反馈列表的反馈状态");
        Map<String, Object> map = new HashMap<>();
        feedbacklistService.setAcceptState(id,EnumPojo.STATE_1);
        PageResult pageResult=new PageResult();
//        pageResult.setStatus(200);
        log.info("通过id修改反馈列表的反馈状态成功");
        return pageResult;
    }
    /**
     * 通过id查询对应的列表数据
     * @param  id 要查询的列表的id
     */
    @RequestMapping("/advanced/selectfeedbackbyid")
    public PageResult selectFeedBackById(int id){
        log.info("通过id查询对应的列表数据");
        Map<String, Object> map = new HashMap<>();
        FeedBackList selectfeedbackbyid = feedbacklistService.selectFeedBackById(id);
        PageResult pageResult=new PageResult();
        pageResult.setData(selectfeedbackbyid);
        log.info("通过id查询对应的列表数据成功");
        return pageResult;
    }
}
